package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.pojo.User;
import com.itheima.service.MenuService;
import com.itheima.service.UserService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Reference
    private UserService userService;

    @Reference
    private MenuService menuService;

    @RequestMapping("/getMenu")
    public Result getMenu(){
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        User user = userService.findByUsername(name);

        List<Menu> menuList = menuService.getMenu(user.getId());

        return new Result(true, "", menuList);
    }


    @RequestMapping("/findAll")
    public Result findAll(){
        List<Menu> list = menuService.findAll();
        return new Result(true,"",list);
    }

}
